<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">工单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="code" class="layui-input" type="text" placeholder="工单编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="物料编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">创建时间：</label>
                                    <div class="layui-input-inline">
                                        <input name="createTime" id="pTime" class="layui-input" type="text"
                                               placeholder="选择时间" autocomplete="off" readonly/>
                                    </div>
                                    <input name="startTime" id="startTime" type="hidden"/>
                                    <input name="endTime" id="endTime" type="hidden"/>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="status" class="common-select-search">
                                            <option value="">工单状态</option>
                                            <option value="not">未完结</option>
                                            <option value="end">完结</option>
                                            <option value="start">开工</option>
                                            <option value="cancel">作废</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="simpleWorkOrderBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                            <button class="layui-btn icon-btn color-reseda importButton">
                                <input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入
                            </button>
                        </div>

                        <div class="lay-btn-rt">
                            <button id="workOrderBtnTemplate" class="layui-btn icon-btn color-green">模板下载</button>
                            <button id="workOrderExport" class="layui-btn icon-btn color-green">导出</button>
                        </div>
                    </div>
                </div>
                <!--               <div class="lay-btn-rows">
                                                    <div class="lay-btn-box">
                                                        <div class="lay-btn-lt">
                                                            <button id="simpleWorkOrderBtnAdd" class="layui-btn icon-btn">添加</button>
                                                        </div>
                                                        <div class="lay-btn-rt">
                                                        </div>
                                                    </div>
                                                </div>-->
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="simpleWorkOrderTable" lay-filter="simpleWorkOrderTable"></table>
        </div>
    </div>
</div>
<style>
    .layui-form.simpleWorkOrderFormBox {
        padding: 20px;
        box-sizing: border-box;
        height: 100%
    }

    .simpleWorkOrderFormBox .open-details-box {
        height: calc(100% - 60px);
        overflow: auto;
        padding-bottom: 20px;
    }

    .simpleWorkOrderFormBox .layui-form-item > .layui-inline {
        margin-right: 0;
    }

    .simpleWorkOrderFormBox .layui-form-item > .layui-inline label {
        min-width: 70px;
        width: auto;
        padding: 9px;
    }

    /*.borderNone .layui-input-inline:not(.borderShow) input[readonly]:not(.layui-unselect),
    .borderNone .layui-input-inline:not(.borderShow) input[readonly]:not(.layui-unselect):hover,
    .borderNone .layui-input-inline:not(.borderShow) input[readonly]:not(.layui-unselect):focus,
    div[lay-id="productionWorkOrderAddDeviceTable"] input[readonly],
    div[lay-id="productionWorkOrderAddDeviceTable"] input[readonly]:hover,
    div[lay-id="productionWorkOrderAddDeviceTable"] input[readonly]:focus {
        border-color: transparent !important;
        outline-color: transparent;
    }*/

    div[lay-id="selectProductDetailTable"] .layui-table-cell,
    div[lay-id="productionWorkOrderAddMaterialTable"] .layui-table-cell {
        height: auto;
        max-height: 80px;
    }

    div[lay-id="selectProductDetailTable"] .layui-table-cell img,
    div[lay-id="productionWorkOrderAddMaterialTable"] .layui-table-cell img {
        max-height: 80px;
    }

    div[lay-id="equipmentTable"] .layui-table-header,
    div[lay-id="materialTable"] .layui-table-header{
        border-width: 1px 0 0 1px;
    }

    .importButton {
        position: relative;
        overflow: hidden;
    }

    .import {
        opacity: 0;
        width: 64px;
        height: 32px;
        left: 0;
        top: 0;
        position: absolute;
        cursor: pointer;
    }

    .simpleWorkOrderFormBoxHeader {
        display: flex;
    }

    .simpleWorkOrderFormBoxHeader > div {
        flex: 1;
    }

    .simpleWorkOrderFormMain {
        width: 100%;
        height: calc(100% - 60px);
        display: flex;
        border: 1px solid #ECECEC;
        box-sizing: border-box;
    }

    .process {
        flex: 1;
        height: 100%;
        background: #F7F8FA;
        border-right: 1px solid #ECECEC;
    }

    .processHeader {
        width: 100%;
        box-sizing: border-box;
        padding: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .processHeaderTitle,
    .equipmentHeaderTitle,
    .materialHeaderTitle {
        width: 70px;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
    }

    .processHeaderBtn > a {
        border: 1px solid #009C5E;
        color: #009C5E;
    }

    .processBox {
        width: 100%;
        height: calc(100% - 79px);
        overflow-y: auto;
    }

    .processBox::-webkit-scrollbar {
        width: 5px;
    }

    .processBoxItem {
        width: 100%;
        height: 60px;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20px;
        border-top: 1px solid transparent;
        cursor: pointer;
        transition: all 300ms;
        font-size: 16px;
        font-weight: 400;
        color: #666666;
    }

    .processBoxItem:hover {
        background-color: #fff;
    }

    .processBoxItem.active {
        background-color: #fff;
        position: relative;
        border-top: 1px solid #ECECEC;
    }

    .processBoxItem.active:before {
        content: "";
        position: absolute;
        display: block;
        width: 4px;
        height: 50px;
        background: #009C5E;
        left: 0;
        top: 5px;
    }

    .processBoxName {
        flex: 1;
    }

    .processBoxItem.active .processBoxName {
        font-weight: bold;
        color: #333333;
    }

    .equipment {
        border-right: 1px solid #ECECEC;
    }

    .equipmentHeader, .materialHeader {
        width: 100%;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 38px;
        padding-right: 8px;
        margin-bottom: 10px;
    }

    .equipmentHeaderBtn > a,
    .materialHeaderBtn > a {
        color: #fff;
    }

    .equipment, .material {
        flex: 2;
        height: 100%;
        overflow-y: scroll;
        padding: 20px 0 0 20px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }

    .equipmentBox, .materialBox {
        flex: 1;
        overflow-y: scroll;
    }

    .processTemplateForm {
        padding: 0 20px 20px;
        box-sizing: border-box;
        height: 100%
    }

    .processTemplateForm .open-details-box {
        height: calc(100% - 40px);
        overflow-y: scroll;
        /*padding-bottom: 20px;*/
    }

    .processTemplateForm .layui-table-body {
        overflow-x: hidden;
    }

    .processTemplateForm div.layui-disabled:hover,
    .selectWorkProcessDeviceTemplate div.layui-disabled:hover,
    .selectWorkProcessMaterialTemplate div.layui-disabled:hover {
        cursor: pointer !important;
    }

    div.layui-table-view[lay-id="equipmentTable"] .layui-table th,
    div.layui-table-view[lay-id="equipmentTable"] .layui-table td,
    div.layui-table-view[lay-id="materialTable"] .layui-table th,
    div.layui-table-view[lay-id="materialTable"] .layui-table td {
        padding: 5px 0;
    }

    div.layui-table-view[lay-id="equipmentTable"] .layui-table-cell,
    div.layui-table-view[lay-id="materialTable"] .layui-table-cell {
        padding: 0 5px;
    }

    .materialBoxTable .layui-table, .equipmentBoxTable .layui-table {
        margin: 0;
    }

    .skuCodeSelectBox {
        width: 100%;
        background-color: #F7F8FA;
        margin-top: 5px;
        box-sizing: border-box;
        position: absolute;
        box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
        border-radius: 5px;
        z-index: 9999;
        display: none;
        max-height: 380px;
        height: auto;
        transition: all 300ms;
    }

    .skuCodeSelectBoxList {
        line-height: 2em;
        cursor: pointer;
        padding: 5px 10px;
        overflow: hidden;
        width: 100%;
        box-sizing: border-box;
        white-space: nowrap;
        transition: all 500ms;
        color: #000;
        background-color: #F7F8FA;
    }

    .skuCodeSelectBoxList:hover {
        background-color: #00833D;
        color: #fff;
    }
    [lay-filter="simpleWorkOrderForm"] .layui-table-cell{
        white-space: pre-line;
    }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="simpleWorkOrderTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="details">详情</a>
    {{# if(d.status == "not"){  }}
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="startWorking">开工</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="cancel">作废</a>
    {{# } }}
    {{# if(d.status == "start"){  }}
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="finish">完结</a>
    {{# } }}

    {{# if(d.status == "end"){  }}
    <a class="layui-btn layui-btn-xs" lay-event="dataStatement">数据报表</a>
    {{# } }}

    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 工单报表表格操作列 -->
<script type="text/html" id="inventoryInoutTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">明细</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="simpleWorkOrderForm">
    <form lay-filter="simpleWorkOrderForm" class="layui-form model-form simpleWorkOrderFormBox">
        <!--  <div class="open-details-box borderNone">
              <div class="layui-form-item layui-row">
                  <input name="id" type="hidden"/>
                  <div class="layui-inline layui-col-md3" id="workPlanCodeBox" style="display: none">
                      <label class="layui-form-label">生产计划编号</label>
                      <div class="layui-input-inline">
                          <input name="workPlanCode" class="layui-input" type="text" readonly="readonly"
                                 placeholder="生产计划编号"/>
                      </div>
                  </div>
                  <div class="layui-inline layui-col-md3">
                      <label class="layui-form-label">关联第三方工单</label>
                      <div class="layui-input-inline">
                          <input name="code" class="layui-input" type="text" lay-verify="required"/>
                      </div>
                  </div>
                  <div class="layui-inline layui-col-md3">
                      <label class="layui-form-label">选择产品</label>
                      <div class="layui-input-inline borderShow">
                          &lt;!&ndash;<input name="skuCode" class="layui-input" type="text" readonly lay-verify="required"/>&ndash;&gt;
                          <input name="skuCode" class="layui-input" type="text" />
                      </div>
                  </div>
                  <div class="layui-inline layui-col-md3">
                      <label class="layui-form-label">选择工序</label>
                      <div class="layui-input-inline">
                          <select name="processId" lay-filter="processId" lay-verify="required" lay-search></select>
                      </div>
                      <input name="nodeNames" type="hidden"/>
                  </div>
                  <div class="layui-inline layui-col-md3">
                      <label class="layui-form-label">生产数量</label>
                      <div class="layui-input-inline">
                          <input name="productionQuantity" class="layui-input" type="text" lay-verify="number"/>
                      </div>
                  </div>
                  <div class="layui-inline layui-col-md3">
                      <label class="layui-form-label">备注描述</label>
                      <div class="layui-input-inline">
                          <input name="remark" class="layui-input" type="text"/>
                      </div>
                  </div>
              </div>
              <div class="layui-row" style="margin:30px 0;">
                  <div class="layui-col-md7" style="padding-right: 25px">
                      <button class="layui-btn" type="button" id="productionWorkOrderAddDeviceTableBtn">添加设备</button>
                      <div class="layui-form-item" style="margin-bottom: 10px;">
                          <div class="open-details-title">关联设备</div>
                      </div>
                      <table class="layui-table" id="productionWorkOrderAddDeviceTable"
                             lay-filter="productionWorkOrderAddDeviceTable"></table>

                  </div>
                  <div class="layui-col-md5">
                      <button class="layui-btn" type="button" id="productionWorkOrderAddMaterialTableBtn">添加产品</button>
                      <div class="layui-form-item" style="margin-bottom: 10px;">
                          <div class="open-details-title">关联产品</div>
                      </div>
                      <table class="layui-table" id="productionWorkOrderAddMaterialTable"
                             lay-filter="productionWorkOrderAddMaterialTable"></table>
                  </div>
              </div>
          </div>-->
        <div class="open-details-box borderNone">
            <div class="layui-form-item simpleWorkOrderFormBoxHeader">
                <input name="id" type="hidden"/>
                <div class="layui-inline" id="workPlanCodeBox" style="display: none">
                    <label class="layui-form-label">生产计划编号</label>
                    <div class="layui-input-inline">
                        <input name="workPlanCode" class="layui-input" type="text" readonly="readonly"
                               placeholder="生产计划编号"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">工单编号</label>
                    <div class="layui-input-inline">
                        <input name="code" class="layui-input" type="text" lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生产产品编号</label>
                    <div class="layui-input-inline">
                        <input name="skuCode" id="skuCode" class="layui-input" type="text" readonly style="cursor: pointer" autocomplete="off"/>
                        <!--lay-verify="required"-->
                        <!--<div class="skuCodeSelectBox" id="skuCodeSelectBox"></div>-->
<!--                        <select name="skuCode" class="layui-input" lay-verify="required" lay-search=""></select>-->
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生产数量</label>
                    <div class="layui-input-inline">
                        <input name="productionQuantity" class="layui-input" type="text" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" lay-verify="number"/>
                        <!--lay-verify="number" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"-->

                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">备注描述</label>
                    <div class="layui-input-inline">
                        <input name="remark" class="layui-input" type="text" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="simpleWorkOrderFormMain">
                <div class="process">
                    <div class="processHeader">
                        <div class="processHeaderTitle">选择工序</div>
                        <div class="processHeaderBtn" id="processHeaderBtn">
                            <a class="layui-btn layui-btn-primary">
                                <i class="layui-icon layui-icon-addition"></i>添加工序
                            </a>
                        </div>
                    </div>
                    <div class="processBox">
                        <ul id="processBoxList">
                            <!--<li class="processBoxItem active">
                                <div class="processBoxName">A工序</div>
                                <div class="processBoxDel">
                                    <i class="layui-icon layui-icon-delete layui-font-18"></i>
                                </div>
                            </li>
                            <li class="processBoxItem">
                                <div class="processBoxName">B工序</div>
                                <div class="processBoxDel">
                                    <i class="layui-icon layui-icon-delete layui-font-18"></i>
                                </div>
                            </li>-->
                        </ul>
                    </div>
                </div>
                <div class="equipment">
                    <div class="equipmentHeader">
                        <div class="equipmentHeaderTitle">关联设备</div>
                        <div class="equipmentHeaderBtn" id="equipmentHeaderBtn">
                            <a class="layui-btn"><i class="layui-icon layui-icon-addition"></i>添加设备</a>
                        </div>
                    </div>
                    <div class="equipmentBox">
                        <div class="equipmentBoxTable">
                            <table class="layui-table" id="equipmentTable" lay-filter="equipmentTable"></table>
                        </div>
                    </div>
                </div>
                <div class="material">
                    <div class="materialHeader">
                        <div class="materialHeaderTitle">关联物料</div>
                        <div class="materialHeaderBtn" id="materialHeaderBtn">
                            <a class="layui-btn"><i class="layui-icon layui-icon-addition"></i>添加物料</a>
                        </div>
                    </div>
                    <div class="materialBox">
                        <div class="materialBoxTable">
                            <table class="layui-table" id="materialTable" lay-filter="materialTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <div class="left-btn"></div>
            <div class="right-btn">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="productionWorkPlanFormSubmit" lay-submit type="button">提交</button>
            </div>
        </div>
    </form>
</script>

<!--选择工序-->
<script type="text/html" id="processTemplate">
    <form lay-filter="processTemplateForm" class="layui-form processTemplateForm">
        <div class="open-details-box">
            <div>
                <table class="layui-table" id="processTable" lay-filter="processTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <div class="left-btn"></div>
            <div class="right-btn">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button id="processClose" class="layui-btn icon-btn" type="button">确认选择</button>
            </div>
        </div>
    </form>
</script>


<script type="text/html" id="simpleWorkOrderFormTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="simpleWorkOrderFormTableBarCancel">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">作废</a>
</script>
<!--选择物料-->
<script type="text/html" id="selectProductDetailTemplate">
    <div class="layui-fluid selectProductDetail">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">物料编号：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="skuCode" class="layui-input" type="text"
                                       placeholder="物料编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn"
                                    lay-filter="selectProductDetailFormSubSearchLog" lay-submit layui-form-keyDownSearch="true"
                                    style="padding: 0 24px;">搜索
                            </button>
                            <button id="selectProductDetailClose" class="layui-btn icon-btn">确认选择</button>
                        </div>
                    </div>
                </div>
                <div class="scroll-table-5-4">
                    <!-- 表格 -->
                    <table class="layui-table" id="selectProductDetailTable"
                           lay-filter="selectProductDetailTable"></table>
                </div>
            </div>
        </div>
    </div>
</script>

<!--选择设备-->
<script type="text/html" id="selectWorkProcessDeviceTemplate">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body selectWorkProcessDeviceTemplate">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">设备编号：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="code" class="layui-input" type="text" placeholder="设备编号" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">设备型号：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="deviceModel" class="layui-input" type="text" placeholder="设备型号" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">设备名称：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="deviceName" class="layui-input" type="text" placeholder="设备名称" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="selectWorkProcessDeviceFormSubSearchLog"
                                    lay-submit style="padding: 0 24px;" layui-form-keyDownSearch="true">
                                搜索
                            </button>
                            <button id="selectWorkProcessDeviceClose" class="layui-btn icon-btn">确认选择</button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <div class="scroll-table-4-5">
                    <table class="layui-table" id="selectWorkProcessDeviceTable"
                           lay-filter="selectWorkProcessDeviceTable"></table>
                </div>
            </div>
        </div>
    </div>
</script>

<!--选择物料-->
<script type="text/html" id="selectWorkProcessMaterialTemplate">
    <div class="layui-fluid">
        <div class="layui-card selectWorkProcessMaterialTemplate">
            <div class="layui-card-body layui-table-page-left">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">物料编号：</label>
                            <div class="layui-input-inline mr0" style="width: 150px">
                                <input name="skuCode" class="layui-input" type="text" placeholder="物料编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">规格：</label>
                            <div class="layui-input-inline mr0" style="width: 150px">
                                <input name="skuSpecValueNames" class="layui-input" type="text" placeholder="规格名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">物料类型</label>
                            <div class="layui-input-inline" style="width: 150px">
                                <select name="productTypeId" id="productTypeId" lay-filter="productTypeId">
                                    <option value="">请选择物料类型</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">物料分类</label>
                            <div class="layui-input-inline" style="width: 150px">
                                <select name="productCategoryId" id="productCategoryId" lay-filter="productCategoryId">
                                    <option value="">请选择物料分类</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn"
                                    lay-filter="selectWorkProcessMaterialFormSubSearchLog" lay-submit layui-form-keyDownSearch="true"
                                    style="padding: 0 24px;">搜索
                            </button>
                            <button id="selectWorkProcessMaterialClose" class="layui-btn" type="button">确认选择</button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <div class="scroll-table-4-5">
                    <table class="layui-table" id="selectWorkProcessMaterialTable"
                           lay-filter="selectWorkProcessMaterialTable"></table>
                </div>

            </div>
        </div>
    </div>
</script>

<!--数据报表-->
<script type="text/html" id="dataStatementTemplate">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <!-- 表格 -->
                <table class="layui-table" id="dataStatementTable"
                       lay-filter="dataStatementTable"></table>
                <table class="layui-table" id="inventoryInoutTable"
                       lay-filter="inventoryInoutTable"></table>

            </div>
        </div>
    </div>
</script>

<!--数据报表领取明细-->
<script type="text/html" id="inventoryInoutDatailsTemplate">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <!-- 表格 -->
                <table class="layui-table" id="inventoryInoutDatailsTable"
                       lay-filter="inventoryInoutDatailsTable"></table>
                <table class="layui-table" id="receiveTable"
                       lay-filter="receiveTable"></table>
            </div>
        </div>
    </div>
</script>

<!--生产产品列表-->
<script type="text/html" id="productDetailList">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form lay-header" name="saleWorkOrderProcessingForm">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">产品名称：</label>
                                        <div class="layui-input-inline">
                                            <input name="skuName" class="layui-input" type="text" placeholder="产品名称"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">产品编码：</label>
                                        <div class="layui-input-inline">
                                            <input name="skuCode" class="layui-input" type="text" placeholder="产品编码"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button class="layui-btn icon-btn" lay-filter="productDetailFormSubSearchLog" lay-submit layui-form-keyDownSearch="true"
                                                type="button">查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="productDetailResets" lay-submit>重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <a id="productDetailAdd" class="layui-btn icon-btn color-reseda">添加</a>
                                <a id="confirmChoose" class="layui-btn icon-btn color-reseda">确认选择</a>
                            </div>
                            <div class="lay-btn-rt"></div>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productDetailTable" lay-filter="productDetailTable"></table>
            </div>
        </div>
    </div>
</script>

<!--生产产品添加-->
<script type="text/html" id="addProductDetail">
    <form lay-filter="addProductDetailForm" class="layui-form" style="padding: 15px 15px 0 0;">
        <input name="productTypeId" type="hidden"/>
        <input name="productCategoryId" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>产品系列</label>
            <div class="layui-input-inline">
                <!--<select name="productId" lay-filter="getProduct" lay-search lay-verify="required"></select>-->
                <input name="productName" class="layui-input" type="text" placeholder="选择产品系列" readonly
                       lay-verify="required" id="productNameInput" style="cursor: pointer"/>
                <input name="productId" type="hidden"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>包装单位</label>
            <div class="layui-input-inline">
                <select name="unitId" lay-filter="getUnit" lay-verify="required"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>包装方案</label>
            <div class="layui-input-inline">
                <select name="packId" lay-verify="required"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>产品名称</label>
            <div class="layui-input-inline">
                <input name="skuName" class="layui-input" type="text" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>产品编号</label>
            <div class="layui-input-inline">
                <input name="skuCode" class="layui-input" type="text" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productAddSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--产品系列列表-->
<script type="text/html" id="productRangeList">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <form class="layui-form toolbar" lay-filter="productRangeList">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">系列名称：</label>
                            <div class="layui-input-inline">
                                <input name="name" class="layui-input" type="text"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="productRangeListSearchLog" lay-submit
                                    type="button">搜索
                            </button>
                            <button id="productRangeListAddClose" class="layui-btn icon-btn" type="button">确认选择</button>
                        </div>
                    </div>
                </form>

                <!-- 表格 -->
                <table class="layui-table" id="productRangeListTable" lay-filter="productRangeListTable"></table>


                <div class="layui-form-item text-right">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                    <button class="layui-btn" lay-filter="productFormSubmit" lay-submit>保存</button>
                </div>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;

        admin.selectSearch();
        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    let dateValue = value.split(" - ");
                    $("#startTime").val(dateValue[0] + " 00:00:00");
                    $("#endTime").val(dateValue[1] + " 23:59:59");
                } else {
                    $("#startTime").val("");
                    $("#endTime").val("");
                }
                setTimeout(function() {$('[lay-filter="formSubSearchLog"]').click()}, 300);
            }
        });
        form.render('select');
        // 渲染表格
        var insTb = table.render({
            elem: '#simpleWorkOrderTable',
            url: config.base + 'production/productionPlan/admin/simpleWorkOrder/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                , {field: 'code', sort: true, title: '工单编号', fixed: 'left'}
                , {field: 'workPlanCode', title: '工单计划编号'}
                , {field: 'skuCode', sort: true, title: '生产产品编号'}
                , {field: 'productionQuantity', sort: true, title: '生产数量'}
                , {field: 'deviceQuantity', title: '生产设备数量'}
                , {
                    field: 'statusDesc', title: '状态'
                }
                , {field: 'creatorName', sort: true, title: '添加人'}
                , {field: 'createTime', sort: true, title: '创建时间'}
                , {align: 'center', toolbar: '#simpleWorkOrderTableBar', title: '操作', width: 240, fixed: 'right'}
            ]],
            done: function (res, curr, count) {
            }
        });

        // 工具条点击事件
        table.on('tool(simpleWorkOrderTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'details') { //详情
                showEditModel(data, 'details');
            } else if (obj.event === 'finish') {
                finish(data);
            } else if (obj.event === 'edit') {
                showEditModel(data, 'edit');
            } else if (obj.event === 'dataStatement') {
                showDataStatement(data);
            } else if (obj.event === 'startWorking') {
                startWorkingModel(data);
            } else if (obj.event === 'cancel') {
                cancelModel(data);
            }
        });


        // 完结
        function finish(data) {
            layer.confirm('确定完结此工单吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/productionPlan/admin/simpleWorkOrder/update', {
                    id: data.id,
                    status: "end"
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('simpleWorkOrderTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'PUT');
            });
        }

        //开工
        function startWorkingModel(data) {
            layer.confirm('确定开工此工单吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/productionPlan/admin/simpleWorkOrder/update', {
                    id: data.id,
                    status: "start"
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('simpleWorkOrderTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'PUT');
            });
        }

        //作废
        function cancelModel(data) {
            layer.confirm('确定作废此工单吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/productionPlan/admin/simpleWorkOrder/cancel/'+data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('simpleWorkOrderTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'PUT');
            });
        }

        //监听排序
        table.on('sort(simpleWorkOrderTable)', function (obj) {
            table.reload('simpleWorkOrderTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });
        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
            return false;
        });

        // 添加按钮点击事件
        $('#simpleWorkOrderBtnAdd').click(function () {
            showEditModel();
        });

        // 显示编辑弹窗
        function showEditModel(data, _type) {
            admin.open({
                type: 1,
                area: ['1665px', '840px'],
                offset: '65px',
                title: data ? (_type === 'details' ? '工单详情' : '工单修改') : '添加工单',
                content: $('#simpleWorkOrderForm').html(),
                success: function () {
                    let simpleWorkOrderData = [], activeSimpleWorkOrderData;

                    /*admin.reqSync('enterprisecab/cabProduct/admin/mostUsedKnifeList/list', {limit: 99999}, res => {
                        if(res.code === 200){
                            loadSelectHtml(res.data,'请输入生产产品编号','skuCode',1,'simpleWorkOrderForm')
                        }
                    });*/


                    if (data) {
                        // 请求工序
                        admin.req('production/productionPlan/admin/simpleWorkOrder/getSimpleWorkOrderVODetails', {id: data.id},
                            res => {
                                if (res.code === 200) {
                                    simpleWorkOrderData = res.data.processVOList;
                                    showProcess(simpleWorkOrderData, _type);
                                } else {
                                    showProcess([], _type);
                                }
                            });

                        $('.simpleWorkOrderFormBoxHeader input').attr('readonly', 'true');
                        $('#workPlanCodeBox').show();
                        $('.simpleWorkOrderFormBoxHeader select').attr('disabled', 'disabled');

                        if (_type === 'details') {
                            $('.simpleWorkOrderFormMain .layui-btn').hide();
                            $('.simpleWorkOrderFormBox button[lay-filter="productionWorkPlanFormSubmit"]').remove();
                        } else {
                            //添加工序按钮
                            $('#processHeaderBtn').click(function () {
                                // 选择工序
                                chooseProcess();
                            });

                            // 添加设备
                            $('#equipmentHeaderBtn').click(function () {
                                if (!activeSimpleWorkOrderData) {
                                    layer.msg('请选择工序', {icon: 5});
                                } else {
                                    chooseDevice('');
                                }
                            });

                            // 添加物料
                            $('#materialHeaderBtn').click(function () {
                                if (!activeSimpleWorkOrderData) {
                                    layer.msg('请选择工序', {icon: 5});
                                }else if(activeSimpleWorkOrderData.deviceList.length == 0){
                                    layer.msg('请先添加关联设备', {icon: 5});
                                } else {
                                    chooseMaterial()
                                }
                            });

                            // 工序作废
                            $('#processBoxList').delegate('li>.processBoxEdit', 'click', function (event) {
                                let _that = $(this);
                                event.stopPropagation();
                                layer.confirm('确定要作废吗？', {offset: '65px', skin: 'layui-layer-admin'}, function (i) {
                                    layer.close(i);
                                    layer.load(2);
                                    admin.req('production/productionPlan/admin/simpleWorkOrder/cancellationWorkOrderProcess', {id: _that.attr('id')}, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            let _acData = simpleWorkOrderData.find(item => item.id == _that.parent('li').attr('id'));
                                            simpleWorkOrderData.splice(simpleWorkOrderData.indexOf(_acData), 1);
                                            _that.parent('li').remove();
                                            if (_that.parent('li').hasClass('active')) {
                                                activeSimpleWorkOrderData = void 0; // 让当前选中的工序清空
                                                showEquipment([]); // 清空关联设备
                                                showMaterial([]); // 清空相关工序
                                            }
                                            layer.msg(res.msg, {icon: 1});
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'PUT');
                                });
                            });


                            // 表单提交事件
                            form.on('submit(productionWorkPlanFormSubmit)', function (d) {
                                /*if (simpleWorkOrderData.length === 0) {
                                    layer.msg('请添加工序', {icon: 5});
                                    return false;
                                }*/
                                d.field.processFormsList = simpleWorkOrderData;
                                admin.req('production/productionPlan/admin/simpleWorkOrder/updateWorkOrder', JSON.stringify(d.field), function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('simpleWorkOrderTable');
                                        layer.closeAll('page');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'put', 'true', 'application/json; charset=utf-8');
                                return false;
                            });

                        }


                        form.val('simpleWorkOrderForm', data);

                    } else {
                        showEquipment([]);
                        showMaterial([]);

                        //1
                        /*  let timer = null;
                        $('.simpleWorkOrderFormBox input[name="skuCode"]').keyup(function () {
                            clearTimeout(timer);
                            timer = setTimeout(() => {
                                productSelection($(this).val().trim());
                            }, 800)
                        });*/

                        //2
                        /*$('#skuCodeSelectBox').delegate('.skuCodeSelectBoxList', 'click', function () {
                            $('.simpleWorkOrderFormBox input[name="skuCode"]').val($(this).text());
                            $('#skuCodeSelectBox').slideUp();
                        });*/

                        // 查询生产产品数据
                        $('#skuCode').click(function () {
                            var skuCodeHtml = admin.open({
                                type: 1,
                                area: ['80%', '80%'],
                                offset: '65px',
                                title: '生产产品列表',
                                content: $('#productDetailList').html(),
                                success: function () {
                                    // 渲染表格
                                    var productDetailTb = table.render({
                                        elem: '#productDetailTable',
                                        url: config.base + 'enterprise/product/admin/productDetailWMS/list',
                                        where: {categoryType: 'production'},
                                        toolbar: true,
                                        defaultToolbar: ["filter"],
                                        page: true,
                                        limit: 5,
                                        limits:[5,10,20,30,40,50,60,70,80],
                                        cellMinWidth: 100,
                                        cols: [[
                                            {type: 'radio',fixed: 'left'}
                                            , {type: 'numbers',title: '序号', fixed: 'left'}
                                            , {field: 'productPic', fixed: 'left', width: 110, title: '图片',templet:function (d) {
                                                    if(d.productPic){
                                                        return '<img src="'+ d.productPic +'"/>';
                                                    }
                                                    return '<img src="assets/images/default-icon.png"/>';
                                                }}
                                            , {field: 'skuName', sort: true, title: '产品名称', fixed: 'left'}
                                            , {field: 'skuCode', sort: true, title: '产品编号'}
                                            , {field: 'skuSpecValueNames', sort: true, title: '规格码', width: 160}
                                            , {field: 'brandName', sort: false, title: '品牌'}
                                            , {field: 'productName', sort: true, title: '所属产品系列', width: 120}
                                            , {field: 'productType', sort: true, title: '产品类型'}
                                            , {field: 'productCategory', sort: true, title: '产品分类'}
                                            , {field: 'unitName', sort: true, title: '单位'}
                                            , {field: 'productSourceDesc', sort: true, title: '物资来源'}
                                            , {field: 'createTime', sort: true, title: '添加时间'}
                                            // , {align: 'center', toolbar: '#productDetailTableBar', title: '操作', width: 100, fixed: 'right'}
                                        ]],
                                    });

                                    // 搜索
                                    form.on('submit(productDetailFormSubSearchLog)', function (data) {
                                        productDetailTb.reload({where: data.field, page: {curr: 1}}, 'data');
                                    });

                                    // 重置搜索
                                    form.on('submit(productDetailResets)', function (data) {
                                        $(".lay-header").find('select').val("");
                                        $(".lay-header").find('input').val("");
                                        let field = data.field;
                                        for (let key in field) {
                                            field[key] = ''
                                        }
                                        productDetailTb.reload({where: field, page: {curr: 1}}, 'data');
                                    });
                                    
                                    $("#productDetailAdd").click(function () {
                                        var addProductDetailHtml = admin.open({
                                            type: 1,
                                            area: ['800px', '500px'],
                                            offset: '65px',
                                            title: '添加生产产品',
                                            content: $('#addProductDetail').html(),
                                            success: function () {
                                                form.render("select");

                                                $('#productNameInput').click(function () {
                                                    let productRangeListIndex = admin.open({
                                                        type: 1,
                                                        area: ['70%', '75%'],
                                                        offset: '75px',
                                                        title: '选择产品系列列表',
                                                        content: $('#productRangeList').html(),
                                                        success: function () {
                                                            let productRangeListTb = table.render({
                                                                elem: '#productRangeListTable',
                                                                url: config.base + 'enterprise/product/admin/product/list',
                                                                where: {categoryType: 'production'},
                                                                page: true,
                                                                cellMinWidth: 100,
                                                                cols: [[
                                                                    {type: 'radio'}
                                                                    , {field: 'name', title: '系列名称'}
                                                                    , {field: 'productCode', title: '产品编码'}
                                                                    , {field: 'productTypeName', title: '类型名称'}
                                                                    , {field: 'productCategoryName', title: '分类名称'}
                                                                ]],
                                                                done: function (res, curr, count) {
                                                                }
                                                            });

                                                            form.on('submit(productRangeListSearchLog)', function (data) {
                                                                productRangeListTb.reload({where: data.field,page: {curr: 1}},'data');
                                                            });

                                                            $('#productRangeListAddClose').click(function () {
                                                                let checkStatus = table.checkStatus('productRangeListTable');
                                                                if (checkStatus.data.length == 0) {
                                                                    layer.msg('请选择数据', {icon: 5});
                                                                } else {
                                                                    $("form input[name='productId']").val(checkStatus.data[0].id);
                                                                    $("form input[name='productName']").val(checkStatus.data[0].name);
                                                                    $("form input[name='productTypeId']").val(checkStatus.data[0].productTypeId);
                                                                    $("form input[name='productCategoryId']").val(checkStatus.data[0].productCategoryId);
                                                                    getProductUnit(checkStatus.data[0].productTypeId)
                                                                    layer.close(productRangeListIndex);
                                                                }
                                                            })
                                                        }
                                                    });
                                                });

                                                // 获取产品系列
                                                /*admin.req('enterprise/product/admin/product/list', {limit:9999, categoryType: 'production'}, function (res) {
                                                    if (res.code==200) {
                                                        var html = "<option value=''>请选择产品系列</option>";
                                                        for (var i = 0; i < res.data.length; i++) {
                                                            html += "<option value='"+res.data[i].id+"'>"+res.data[i].name+"("+res.data[i].specCode+")</option>";
                                                        }
                                                        $("form select[name='productId']").html(html);
                                                        form.render('select');
                                                        form.on('select(getProduct)', function (d) {
                                                            if(d.value != ""){
                                                                for (var i = 0; i < res.data.length; i++) {
                                                                    if(d.value == res.data[i].id){
                                                                        $("form input[name='productTypeId']").val(res.data[i].productTypeId);
                                                                        $("form input[name='productCategoryId']").val(res.data[i].productCategoryId);
                                                                        getProductUnit(res.data[i].productTypeId)
                                                                    }
                                                                }
                                                            }
                                                            form.render();
                                                        })
                                                    } else {
                                                        layer.msg('获取产品系列失败', {icon: 2, time: 1000});
                                                    }
                                                }, 'GET', false);*/

                                                // 查询包装单位
                                                function getProductUnit(productType){
                                                    //请求包装单位
                                                    admin.req('enterprise/product/admin/productUnit/list', {type: 0, page: 1, limit: 9999, isBaseUnit: false, productType: productType}, res => {
                                                        if (res.code === 200) {
                                                            loadSelectHtml(res.data, '包装单位', 'unitId', 2, 'addProductDetailForm')
                                                        } else {
                                                            loadSelectHtml([], '包装单位', 'unitId', 2, 'addProductDetailForm')
                                                        }
                                                    }, 'get', false);
                                                }

                                                // 选择包装单位
                                                form.on('select(getUnit)', function (d) {
                                                    if(d.value){
                                                        // 查询包装方案
                                                        admin.req('enterprise/product/admin/productPack/getByUnitId', {productUnitId: d.value}, function (res) {
                                                            if (res.code === 200) {
                                                                let packList = []
                                                                res.data.forEach(item => {
                                                                    if (item.isDeleted) {
                                                                    packList.push(item)
                                                                }
                                                            })
                                                                loadSelectHtml(packList, "包装方案", "packId", 2, 'addProductDetailForm');
                                                            } else {
                                                                loadSelectHtml([], '包装方案', 'packId', 2, 'addProductDetailForm')
                                                            }
                                                        }, 'get', false);
                                                    }else{
                                                        loadSelectHtml([], '包装方案', 'packId', 2, 'addProductDetailForm')
                                                    }
                                                })

                                                // 表单提交事件
                                                form.on('submit(productAddSubmit)', function (d) {
                                                    layer.load(2);
                                                    admin.req('enterprise/product/admin/productDetailWMS/add', d.field, function (res) {
                                                        layer.closeAll('loading');
                                                        if (res.code == 200) {
                                                            layer.msg(res.msg, {icon: 1});
                                                            table.reload('productDetailTable');
                                                            layer.close(addProductDetailHtml);
                                                        } else {
                                                            layer.msg(res.msg, {icon: 2});
                                                        }
                                                    },'POST');
                                                    return false;
                                                });

                                            }
                                        })
                                    })

                                    $('#confirmChoose').click(function () {
                                        let checkStatus = table.checkStatus('productDetailTable');
                                        if (checkStatus.data.length == 0) {
                                            layer.msg('请选择生产产品', {icon: 5});
                                        } else {
                                            $("#skuCode").val(checkStatus.data[0].skuCode);
                                            layer.close(skuCodeHtml);
                                            activeSimpleWorkOrderData = void 0;
                                            if ($('.simpleWorkOrderFormBox input[name="productionQuantity"]').val().trim() == '' || $("#skuCode").val().trim() == '') {
                                                return false;
                                            }else {
                                                getMaterialData($("#skuCode").val().trim(), $('.simpleWorkOrderFormBox input[name="productionQuantity"]').val().trim())
                                            }
                                        }
                                    })

                                }
                            })
                        })


                        //根据物料编号和生产数量带出关联物料
                       /* $('.simpleWorkOrderFormBox input[name="skuCode"]').change(function () {
                            activeSimpleWorkOrderData = void 0;
                            $(this).val($(this).val().trim());
                            if ($('.simpleWorkOrderFormBox input[name="productionQuantity"]').val().trim() == '' || $(this).val().trim() == '') {
                                return false;
                            }
                            getMaterialData($(this).val().trim(), $('.simpleWorkOrderFormBox input[name="productionQuantity"]').val().trim())
                        });
                        #confirmChoose*/

                        $('.simpleWorkOrderFormBox input[name="productionQuantity"]').change(function () {
                            activeSimpleWorkOrderData = void 0;
                            $(this).val($(this).val().trim());
                            if ($('.simpleWorkOrderFormBox input[name="skuCode"]').val().trim() == '' || $(this).val().trim() == '') {
                                return false;
                            }
                            getMaterialData($('.simpleWorkOrderFormBox input[name="skuCode"]').val().trim(), $(this).val().trim())
                        });


                        //添加工序按钮
                        $('#processHeaderBtn').click(function () {
                            chooseProcess()
                        });  // 选择工序

                        // 添加设备
                        $('#equipmentHeaderBtn').click(function () {
                            if (!activeSimpleWorkOrderData) {
                                layer.msg('请选择工序', {icon: 5});
                            } else {
                                chooseDevice();
                            }
                        });

                        // 添加物料
                        $('#materialHeaderBtn').click(function () {
                            if (!activeSimpleWorkOrderData) {
                                layer.msg('请选择工序', {icon: 5});
                            }else if(activeSimpleWorkOrderData.deviceList.length == 0){
                                layer.msg('请先添加关联设备', {icon: 5});
                            }else {
                                chooseMaterial()
                            }
                        });

                        // 表单提交事件
                        form.on('submit(productionWorkPlanFormSubmit)', function (d) {
                            /*if (simpleWorkOrderData.length === 0) {
                                layer.msg('请添加工序', {icon: 5});
                                return false;
                            }*/
                            d.field.processFormsList = simpleWorkOrderData;
                            admin.req('production/productionPlan/admin/simpleWorkOrder/addSimpleWorkOrder', JSON.stringify(d.field), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('simpleWorkOrderTable');
                                    layer.closeAll('page');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', 'true', 'application/json; charset=utf-8');
                            return false;
                        });
                    }
                    form.render('select');
                    //3
                    /*function productSelection(_value) {
                        if (_value == '') {
                            $('#skuCodeSelectBox').slideUp();
                            return false
                        }
                        admin.req('production/productionPlan/admin/simpleWorkOrder/list', {skuCode: _value}, res => {
                            if (res.code === 200) {
                                $('#skuCodeSelectBox').html('');
                                if (res.data.length > 0) {
                                    let html = '';
                                    res.data.forEach(item => {
                                        html += '<div class="skuCodeSelectBoxList">' + item.skuCode + '</div>'
                                    });
                                    $('#skuCodeSelectBox').html(html);
                                    $('#skuCodeSelectBox').slideDown();
                                } else {
                                    $('#skuCodeSelectBox').slideUp();
                                }
                            }
                        })
                    }*/

                    // 选择工序
                    function chooseProcess() {
                        if ($('.simpleWorkOrderFormBox input[name="skuCode"]').val().trim() == '') {
                            $('.simpleWorkOrderFormBox input[name="skuCode"]').focus();
                            layer.msg('请输入生产产品编号', {icon: 5});
                            return false;
                        }
                        if ($('.simpleWorkOrderFormBox input[name="productionQuantity"]').val().trim() == '') {
                            $('.simpleWorkOrderFormBox input[name="productionQuantity"]').focus();
                            layer.msg('请填写生产数量', {icon: 5});
                            return false;
                        }
                        let processPop = admin.open({
                            type: 1,
                            area: ['1200px', '780px'],
                            offset: '75px',
                            title: '选择工序',
                            content: $('#processTemplate').html(),
                            success: function () {
                                let processTB = table.render({
                                    elem: '#processTable',
                                    url: config.base + 'enterprise/product/admin/processInfo/list',
                                    page: false,
                                    where: {page: 1, limit: 99999},
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {field: 'nodeCodes', title: '工序编号'}
                                        , {field: 'nodeNames', title: '工序名称'}
                                        , {field: 'createTime', title: '创建时间', align: 'center'}
                                    ]],
                                    done: function (res, curr, count) {
                                        $('.processTemplateForm .layui-table-body input').attr('disabled', 'disabled');

                                    }, parseData: function (res, curr, count) {
                                        let resData = [];
                                        resData = res.data.filter(item => simpleWorkOrderData.every(item1 => item1.processId !== item.id));
                                        res.data = resData;
                                        // res.count = Number(res.count) - simpleWorkOrderData.length;
                                        return res;
                                    }
                                });

                                //搜索
                                form.on('submit(processFormSubSearchLog)', function (data) {
                                    processTB.reload({where: data.field, page: {curr: 1}}, 'data');
                                });

                                table.on('row(processTable)', function (obj) {
                                    let flag = !obj.tr.find(':checkbox:first').prop('checked');
                                    obj.tr.find(':checkbox').prop('checked', flag);
                                    if (flag) {
                                        obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                                    } else {
                                        obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                                    }
                                    layui.each(table.cache.processTable, function (i, l) {
                                        if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                                            l.LAY_CHECKED = flag;
                                        }
                                    });
                                });

                                //确认选择
                                $('#processClose').click(function () {
                                    let checkStatus = table.checkStatus('processTable');
                                    if (checkStatus.data.length === 0) {
                                        layer.msg('请选择工序', {icon: 5});
                                        return false;
                                    } else {
                                        checkStatus.data.forEach((item, index) => {
                                            item.processId = item.id;
                                            item.deviceList = [];
                                            item.materialList = [];
                                        });
                                        simpleWorkOrderData = [...simpleWorkOrderData, ...checkStatus.data];
                                        layer.close(processPop);
                                        showProcess(checkStatus.data)
                                    }
                                });
                            }
                        });
                    }

                    // 渲染工序
                    function showProcess(_data, processType) {
                        if (_data.length === 0) {
                            return false
                        } else {
                            layer.load(2);
                            let html = '';
                            _data.forEach((item, index) => {
                                if ((processType == 'details' && index == 0) || processType == 'edit' && index == 0) {
                                    html += `<li class="processBoxItem active" id="${item.processId}" type="${processType || ''}">
                                                <div class="processBoxName">${item.nodeNames}</div>
                                                 ${processType == "details" ? '' : (processType == "edit" ?
                                        '<div class="processBoxEdit" id="' + item.id + '"><a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">作废</a></div>' :
                                        '<div class="processBoxDel"><i class="layui-icon layui-icon-delete layui-font-18"></i></div>')}</li>`;


                                    activeSimpleWorkOrderData = item;
                                    admin.req('production/productionPlan/admin/simpleWorkOrder/getWorkOrderDeviceAndMaterial',
                                        {processId: item.processId, workOrderId: data.id}, res => {
                                            if (res.code === 200) {
                                                activeSimpleWorkOrderData.deviceList = res.data.deviceList;
                                                activeSimpleWorkOrderData.materialList = res.data.materialList;
                                                showEquipment(activeSimpleWorkOrderData.deviceList);
                                                showMaterial(activeSimpleWorkOrderData.materialList);
                                            } else {
                                                showEquipment([]);
                                                showMaterial([])
                                            }
                                        })

                                } else {
                                    html += `<li class="processBoxItem" id="${item.processId}" type="${processType || ''}">
                                                <div class="processBoxName">${item.nodeNames}</div>
                                                ${processType == "details" ? '' : (processType == "edit" ?
                                        '<div class="processBoxEdit" id="' + item.id + '"><a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">作废</a></div>' :
                                        '<div class="processBoxDel"><i class="layui-icon layui-icon-delete layui-font-18"></i></div>')}</li>`
                                }
                            });
                            layer.closeAll('loading');
                            $('#processBoxList').append(html);

                        }
                    }

                    // 工序点击事件
                    $('#processBoxList').delegate('li', 'click', function () {
                        $(this).addClass('active').siblings().removeClass('active');
                        let _processId = $(this).attr('id');
                        activeSimpleWorkOrderData = simpleWorkOrderData[$(this).index()];
                        if ($(this).attr('type') == 'details' || $(this).attr('type') == 'edit') {
                            layer.load(2);
                            admin.req('production/productionPlan/admin/simpleWorkOrder/getWorkOrderDeviceAndMaterial',
                                {processId: _processId, workOrderId: data.id}, res => {
                                    layer.closeAll('loading');
                                    if (res.code === 200) {
                                        let deviceListData = res.data.deviceList.length >= activeSimpleWorkOrderData.deviceList.length ? res.data.deviceList : activeSimpleWorkOrderData.deviceList,
                                            materialListData = res.data.materialList.length >= activeSimpleWorkOrderData.materialList.length ? res.data.materialList : activeSimpleWorkOrderData.materialList;
                                        activeSimpleWorkOrderData.deviceList = deviceListData;
                                        activeSimpleWorkOrderData.materialList = materialListData;
                                        showEquipment(activeSimpleWorkOrderData.deviceList);
                                        showMaterial(activeSimpleWorkOrderData.materialList);
                                    } else {
                                        showEquipment([]);
                                        showMaterial([])
                                    }
                                })
                        } else {
                            showEquipment(activeSimpleWorkOrderData.deviceList);
                            showMaterial(activeSimpleWorkOrderData.materialList);
                        }
                    });

                    // 工序删除事件
                    $('#processBoxList').delegate('li>.processBoxDel', 'click', function (event) {
                        let _acData = simpleWorkOrderData.find(item => item.id == $(this).parent('li').attr('id'));
                        simpleWorkOrderData.splice(simpleWorkOrderData.indexOf(_acData), 1);
                        $(this).parent('li').remove();

                        //判断是否是当前选中的工序
                        if ($(this).parent('li').hasClass('active')) {
                            activeSimpleWorkOrderData = void 0; // 让当前选中的工序清空
                            showEquipment([]); // 清空关联设备
                            showMaterial([]); // 清空相关工序
                        }
                        event.stopPropagation();
                    });

                    //选择设备
                    function chooseDevice() {
                        let selectWorkProcessDeviceTemplate = admin.open({
                            type: 1,
                            title: '选择' + activeSimpleWorkOrderData.nodeNames + '关联设备',
                            area: ['1450px', '750px'],
                            offset: '90px',
                            content: $('#selectWorkProcessDeviceTemplate').html(),
                            success: function () {
                                form.render("select");
                                // 渲染表格
                                let selectWorkProcessDeviceTable = table.render({
                                    elem: '#selectWorkProcessDeviceTable',
                                    url: config.base + 'production/productionPlan/admin/productionPlan/getProductionDeviceByProcessId?processId=' + activeSimpleWorkOrderData.processId,
                                    page: true,
                                    cellMinWidth: 100,
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {field: 'deviceCode', sort: true, title: '设备编码'}
                                        , {field: 'deviceModel', sort: true, title: '设备型号'}
                                        , {field: 'deviceName', sort: true, title: '设备名称'}
                                        , {field: 'createTime', title: '创建时间', align: 'center'}
                                    ]],
                                    done: function (res, curr, count) {
                                        $('.selectWorkProcessDeviceTemplate .layui-table-body input').attr('disabled', 'disabled');
                                    },
                                    parseData: function (res) {
                                        /*let resData = [];
                                        resData = res.data.filter(item => activeSimpleWorkOrderData.deviceList.every(item1 => item1.deviceCode !== item.deviceCode));
                                        res.data = resData;
                                        if (activeSimpleWorkOrderData.deviceList.length == res.count) {
                                            return res
                                        } else {
                                            if (res.data.length === 0) {
                                                selectWorkProcessDeviceTable.reload({
                                                    where: {},
                                                    page: {curr: 1},
                                                    limit: activeSimpleWorkOrderData.deviceList.length + 10
                                                }, 'data');
                                            }
                                            return res;
                                        }*/

                                        let resData = res.data.filter(item => activeSimpleWorkOrderData.deviceList.every(item1 => item1.deviceCode !== item.deviceCode)),
                                            urlOne = config.base + 'production/productionPlan/admin/productionPlan/getProductionDeviceByProcessId?processId=' + activeSimpleWorkOrderData.processId;
                                        if (res.count == 0 && selectWorkProcessDeviceTable.config.url == urlOne) {
                                            selectWorkProcessDeviceTable.config.url = config.base + 'enterprise/device/admin/device/list';
                                            selectWorkProcessDeviceTable.reload({}, 'data');
                                        } else {
                                            res.data = resData;
                                            if (activeSimpleWorkOrderData.deviceList.length == res.count) {
                                                return res
                                            } else {
                                                if (res.data.length === 0) {
                                                    selectWorkProcessDeviceTable.reload({
                                                        where: {},
                                                        page: {curr: 1},
                                                        limit: activeSimpleWorkOrderData.deviceList.length + 10
                                                    }, 'data');
                                                }
                                                return res;
                                            }
                                        }


                                    }
                                });

                                //行事件
                                table.on('row(selectWorkProcessDeviceTable)', function (obj) {
                                    let flag = !obj.tr.find(':checkbox:first').prop('checked');
                                    obj.tr.find(':checkbox').prop('checked', flag);
                                    if (flag) {
                                        obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                                    } else {
                                        obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                                    }
                                    layui.each(table.cache.selectWorkProcessDeviceTable, function (i, l) {
                                        if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                                            l.LAY_CHECKED = flag;
                                        }
                                    });
                                });

                                // 搜索
                                form.on('submit(selectWorkProcessDeviceFormSubSearchLog)', function (data) {
                                    selectWorkProcessDeviceTable.reload({
                                        where: data.field,
                                        page: {curr: 1}
                                    }, 'data');
                                });

                                // 确认选择
                                $('#selectWorkProcessDeviceClose').click(function () {
                                    let checkStatus = table.checkStatus('selectWorkProcessDeviceTable'); //test即为基础参数id对应的值
                                    if (checkStatus.data.length == 0) {
                                        layer.msg("请选择设备", {icon: 2, time: 1000});
                                    } else {
                                        checkStatus.data.forEach(item => {
                                            item.productionQuantity = '';
                                            item.isLocal = true;
                                        });
                                        activeSimpleWorkOrderData.deviceList = [...activeSimpleWorkOrderData.deviceList, ...checkStatus.data];
                                        // 渲染表格
                                        showEquipment(activeSimpleWorkOrderData.deviceList);
                                        layer.close(selectWorkProcessDeviceTemplate);
                                        $(".open-details-box").scrollTop($('.open-details-box').height());
                                    }
                                });
                            }
                        })
                    }

                    // 渲染设备
                    function showEquipment(_data) {
                        // 渲染设备table
                        table.render({
                            elem: '#equipmentTable',
                            page: false,
                            data: _data,
                            limit: Number.MAX_VALUE,
                            cellMinWidth: 100,
                            cols: [[
                                {type: 'numbers', title: '序号', width: 60}
                                , {field: 'deviceCode', title: '设备编号'}
                                , {field: 'deviceModel', title: '设备类型'}
                                , {field: 'deviceName', title: '设备名称'}
                                , {
                                    field: 'productionQuantity', title: '计划生产数量', width: 120, templet: function (d) {
                                        return '<input class="layui-input productionQuantity" placeholder="非必填" style="height: 28px;" type="text" ' +
                                            'value="' + d.productionQuantity + '" onkeyup="this.value=this.value.replace(/^0(0+|\\d+)|[^\\d]+/g,\'\')"/>'
                                    }
                                },
                                data ? (_type === 'details' ? '' : {
                                    templet: d =>
                                        d.isLocal ? '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>' :
                                            '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="cancel">作废</a>'
                                    , title: '操作', width: 50
                                }) : ({toolbar: '#simpleWorkOrderFormTableBar', title: '操作', width: 50})
                            ]],
                            done: function (res, curr, count) {
                                if (data && _type === 'details') {
                                    $('.productionQuantity').attr('readonly', "readonly")
                                }
                            }
                        });

                        // 修改设备计划生产数量
                        $("body").delegate("[lay-id='equipmentTable'] input.productionQuantity", "change", function () {
                            if (activeSimpleWorkOrderData.deviceList[$(this).parents('tr').index()]) {
                                activeSimpleWorkOrderData.deviceList[$(this).parents('tr').index()].productionQuantity = $(this).val().trim();
                            }
                        });

                        // 设备
                        table.on('tool(equipmentTable)', function (obj) {
                            if (obj.event === 'del') { //删除
                                activeSimpleWorkOrderData.deviceList.splice(obj.tr.index(), 1);
                                obj.del();
                            } else if (obj.event === 'cancel') { // 作废
                                layer.confirm('确定要作废吗？', {offset: '65px', skin: 'layui-layer-admin'}, function (i) {
                                    layer.close(i);
                                    layer.load(2);
                                    admin.req('production/productionPlan/admin/simpleWorkOrder/cancellationWorkOrderDevice', {id: obj.data.id}, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            activeSimpleWorkOrderData.deviceList.splice(obj.tr.index(), 1);
                                            obj.del();
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'PUT');
                                });
                            }
                        });
                    }

                    // 选择物料
                    function chooseMaterial() {
                        let selectWorkProcessMaterialTemplate = admin.open({
                            type: 1,
                            title: '选择排产物料',
                            area: ['1450px', '750px'],
                            offset: '100px',
                            content: $('#selectWorkProcessMaterialTemplate').html(),
                            success: function () {
                                // 渲染表格
                                let selectWorkProcessMaterialTable = table.render({
                                    elem: '#selectWorkProcessMaterialTable',
                                    url: config.base + 'enterprise/product/admin/productDetail/list',
                                    where:{categoryType:'purchase'},
                                    page: true,
                                    cellMinWidth: 100,
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {field: 'skuCode', sort: true, title: '物料编号'}
                                        , {field: 'skuName', title: '物料名称', align: 'center'}
                                        , {field: 'unitName', title: '物料单位', align: 'center'}
                                        , {field: 'quantityStock', title: '库存数量', align: 'center'}
                                        , {field: 'skuSpecValueNames', title: '物料规格', align: 'center'}
                                        , {field: 'categoryName', title: '物料分类', align: 'center'}
                                        , {field: 'productTypeName', title: '物料类型', align: 'center'}
                                        , {field: 'createTime', title: '创建时间', align: 'center'}
                                    ]],
                                    done: function (res, curr, count) {
                                        $('.selectWorkProcessMaterialTemplate .layui-table-body input').attr('disabled', 'disabled');
                                    },
                                    parseData: function (res, curr, count) {
                                        let resData = [];
                                        resData = res.data.filter(item => activeSimpleWorkOrderData.materialList.every(item1 => item1.defaultMaterialSkuCode !== item.skuCode));
                                        res.data = resData;
                                        if (activeSimpleWorkOrderData.materialList.length == res.count) {
                                            return res
                                        } else {
                                            if (res.data.length === 0) {
                                                selectWorkProcessMaterialTable.reload({
                                                    where: {},
                                                    page: {curr: 1},
                                                    limit: activeSimpleWorkOrderData.materialList.length + 10
                                                }, 'data');
                                            }
                                            return res;
                                        }
                                    }
                                });

                                //行事件
                                table.on('row(selectWorkProcessMaterialTable)', function (obj) {
                                    let flag = !obj.tr.find(':checkbox:first').prop('checked');
                                    obj.tr.find(':checkbox').prop('checked', flag);
                                    if (flag) {
                                        obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                                    } else {
                                        obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                                    }
                                    layui.each(table.cache.selectWorkProcessMaterialTable, function (i, l) {
                                        if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                                            l.LAY_CHECKED = flag;
                                        }
                                    });
                                });

                                // 获取物料类型
                                admin.reqSync('enterprise/product/admin/productType/getProductTypeVOAll', {}, function (res) {
                                    if (res.code == 200) {
                                        $.each(res.data, function (index, item) {
                                            $("#productTypeId").append(new Option(item.name, item.id));
                                        })
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'GET');

                                // 获取物料分类
                                admin.reqSync('enterprise/product/admin/productCategory/getAll', {'categoryType':'purchase'}, function (res) {
                                    if (res.code == 200) {
                                        $.each(res.data, function (index, item) {
                                            $("#productCategoryId").append(new Option(item.name, item.id));
                                        })
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'GET');

                                form.render("select");

                                // 搜索
                                form.on('submit(selectWorkProcessMaterialFormSubSearchLog)', function (data) {
                                    selectWorkProcessMaterialTable.reload({
                                        where: data.field,
                                        page: {curr: 1}
                                    }, 'data');
                                });

                                // 确认选择
                                $('#selectWorkProcessMaterialClose').click(function () {
                                    let checkStatus = table.checkStatus('selectWorkProcessMaterialTable'); //test即为基础参数id对应的值
                                    let dataS = [];
                                    if (checkStatus.data.length == 0) {
                                        layer.msg("请选择物料", {icon: 2, time: 1000});
                                    } else {
                                        checkStatus.data.forEach(item => {
                                            dataS.push({
                                                id: item.id,
                                                quantity: 1,
                                                productPic: item.productPic,
                                                defaultMaterialSkuCode: item.skuCode,
                                                defaultSkuName: item.skuName,
                                                defaultSkuSpecValue: item.oldSpecCode,
                                                oldSpecCode:item.oldSpecCode,
                                                isDel: true,
                                                materialSkuCode: item.skuCode,
                                                isLocal: true
                                            })
                                        });
                                        activeSimpleWorkOrderData.materialList = [...activeSimpleWorkOrderData.materialList, ...dataS];
                                        showMaterial(activeSimpleWorkOrderData.materialList);
                                        layer.close(selectWorkProcessMaterialTemplate);
                                    }
                                });
                            }
                        })
                    }

                    // 渲染物料
                    function showMaterial(_data) {
                        // 渲染设备table
                        table.render({
                            elem: '#materialTable',
                            page: false,
                            data: _data,
                            limit: Number.MAX_VALUE,
                            cellMinWidth: 100,
                            cols: [[
                                {type: 'numbers', title: '序号', width: 40}
                                , {
                                    field: 'productPic',
                                    title: '物料图片',
                                    width: 80,
                                    templet:function (d) {
                                        if(d.productPic){
                                            return '<img src="'+ d.productPic +'" style="cursor: pointer"/>';
                                        }
                                        return '<img src="assets/images/default-icon.png" style="cursor: pointer"/>';
                                    }
                                }
                                , {field: 'defaultSkuName', title: '物料名称', width: 90,}
                                , {field: 'defaultMaterialSkuCode', title: '物料编号'}
                                , {field: 'oldSpecCode', title: '物料规格码', width: 90,}
                                , {
                                    field: 'quantity', title: '预计所需数量\n(按基础数量)', width: 120, templet: function (d) {
                                        return '<input class="layui-input productionQuantity" lay-verify="number" style="height: 28px;" type="text" ' +
                                            'value="' + d.quantity + '" onkeyup="this.value=this.value.replace(/^0(0+|\\d+)|[^\\d]+/g,\'\')"/>'
                                    }
                                },
                                // data ? '' : { align: 'center',title: '操作', width: 60, templet: d => d.isDel ? '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>' : "" }
                                data ? (_type === 'details' ? '' : {
                                        templet: d =>
                                            d.isLocal ? '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>' :
                                                '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="cancel">作废</a>'
                                        , title: '操作', width: 50
                                    }) :
                                    ({toolbar: '#simpleWorkOrderFormTableBar', title: '操作', width: 50})
                            ]],
                            done: function (res, curr, count) {
                                if (data && _type === 'details') {
                                    $('.productionQuantity').attr('readonly', "readonly")
                                }
                            }
                        });

                        // 修改设备计划生产数量
                        $("body").delegate("[lay-id='materialTable'] input.productionQuantity", "change", function () {
                            if (activeSimpleWorkOrderData.materialList[$(this).parents('tr').index()]) {
                                activeSimpleWorkOrderData.materialList[$(this).parents('tr').index()].quantity = $(this).val().trim();
                            }
                        });

                        // 设备删除
                        table.on('tool(materialTable)', function (obj) {
                            let data = obj.data;
                            if (obj.event === 'del') { //删除
                                activeSimpleWorkOrderData.materialList.splice(obj.tr.index(), 1);
                                obj.del();
                            } else if (obj.event === 'cancel') { // 作废
                                layer.confirm('确定要作废吗？', {offset: '65px', skin: 'layui-layer-admin'}, function (i) {
                                    layer.close(i);
                                    layer.load(2);
                                    admin.req('production/productionPlan/admin/simpleWorkOrder/cancellationWorkOrderMaterial', {id: obj.data.id}, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            activeSimpleWorkOrderData.materialList.splice(obj.tr.index(), 1);
                                            obj.del();
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'PUT');
                                });
                            }
                        });
                    }

                    // 根据物料编号和生产数量请求关联物料
                    function getMaterialData(_skuCode, _productionQuantity) {
                        layer.load(2);
                        admin.req('production/productionPlan/admin/simpleWorkOrder/getMaterialForecastData', {
                            skuCode: _skuCode,
                            productionQuantity: _productionQuantity
                        }, res => {
                            if (res.code === 200) {
                                simpleWorkOrderData = res.data;
                                $('#processBoxList').html('');
                                showProcess(simpleWorkOrderData)
                            } else {
                                simpleWorkOrderData = [];
                                $('#processBoxList').html('');
                                showProcess(simpleWorkOrderData);

                            }
                            showEquipment([]);
                            showMaterial([]);
                            layer.closeAll('loading');
                        }, 'get');
                    }

                }
            });
        }

        //显示数据报表弹窗
        function showDataStatement(data) {
            admin.open({
                type: 1,
                area: ['82%', '840px'],
                offset: '65px',
                title: '查看工单报表',
                content: $('#dataStatementTemplate').html(),
                success: function () {
                    //工单
                    let productionWorkOrderData = [], workOrderCode = data.code, skuCode = data.skuCode;
                    productionWorkOrderData.push(data);
                    var dataStatementTb = table.render({
                        elem: '#dataStatementTable',
                        page: false,
                        data: productionWorkOrderData,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', sort: true, title: '关联工单编号'}
                            , {field: 'skuCode', title: '生产物料'}
                            , {field: 'productionQuantity', sort: true, title: '物料数量'}
                            , {field: 'unitName', title: '单位'}
                            , {field: 'remark', title: '备注描述'}
                            , {field: 'creatorName', sort: true, title: '创建人'}
                            , {field: 'createTime', sort: true, title: '创建时间'}
                            , { field: 'statusDesc', title: '状态'}
                            //, {align: 'center', toolbar: '#simpleWorkOrderTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                        }
                    });

                    // 渲染表格
                    var inventoryInoutTb = table.render({
                        elem: '#inventoryInoutTable',
                        url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInout/list?workOrderId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'skuCode', sort: true, title: '料号'}
                            , {field: 'productTypeName', sort: true, title: '物料类型'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuSpec', sort: true, title: '规格码'}
                            , {field: 'deviceQuantity', title: '供应商'}
                            , {field: 'estimatedQuantity', title: '预估数量'}
                            , {field: 'receiveSum', title: '领用总数量'}
                            , {field: 'receiveAmount', title: '领用总金额'}
                            /*, {field: 'creatorName', sort: true, title: '添加人'}
                            , {field: 'createTime', sort: true, title: '发货时间'}*/
                            , {align: 'center', toolbar: '#inventoryInoutTableBar', title: '操作', width: 100}
                        ]],
                        done: function (res, curr, count) {
                        }
                    });
                    // 工具条点击事件
                    table.on('tool(inventoryInoutTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'details') { //明细
                            showInventoryInoutModel(data, workOrderCode, skuCode);
                        }
                    });
                }
            });
        }

        //显示领取明细弹窗
        function showInventoryInoutModel(data, workOrderCode, skuCode) {
            admin.open({
                type: 1,
                area: ['82%', '840px'],
                offset: '65px',
                title: '领用明细',
                content: $('#inventoryInoutDatailsTemplate').html(),
                success: function () {
                    //工单
                    let inventoryInoutData = [];
                    inventoryInoutData.push(data);
                    var inventoryInoutDatailsTb = table.render({
                        elem: '#inventoryInoutDatailsTable',
                        page: false,
                        data: inventoryInoutData,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {
                                field: 'code', sort: true, title: '工单编号', templet: function (d) {
                                    return workOrderCode;
                                }
                            }
                            , {
                                field: 'skuCode', sort: true, title: '生产物料', templet: function (d) {
                                    return skuCode;
                                }
                            }
                            , {field: 'skuCode', sort: true, title: '料号'}
                            , {field: 'productTypeName', sort: true, title: '物料类型'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuSpec', sort: true, title: '规格码'}
                            , {field: 'deviceQuantity', title: '供应商'}
                            , {field: 'estimatedQuantity', title: '预估数量'}
                            , {field: 'receiveSum', title: '领用总数量'}
                            , {field: 'receiveAmount', title: '领用总金额'}
                            //, {align: 'center', toolbar: '#simpleWorkOrderTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                        }
                    });

                    // 渲染表格
                    var receiveTb = table.render({
                        elem: '#receiveTable',
                        url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInoutDetail/list?inoutId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', sort: true, title: '领用记录编号'}
                            , {field: 'processName', sort: true, title: '所属工序'}
                            , {field: 'deviceCode', title: '所属机床'}
                            , {field: 'quantity', sort: true, title: '领取数量'}
                            , {field: 'unitName', title: '单位'}
                            , {field: 'receiveAmount', title: '金额'}
                            , {field: 'remark', title: '备注描述'}
                            , {field: 'creatorName', sort: true, title: '领取人'}
                            , {field: 'createTime', sort: true, title: '领取时间'}
                            /*, {field: 'createTime', sort: true, title: '出货状态'}*/
                        ]],
                        done: function (res, curr, count) {
                        }
                    });
                    // 工具条点击事件
                    /*              table.on('tool(inventoryInoutTable)', function (obj) {
                                      var data = obj.data;
                                      if (obj.event === 'details') { //明细
                                          showInventoryInoutModel(data);
                                      }
                                  });*/
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/productionPlan/admin/simpleWorkOrder/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 模板下载
        $("#workOrderBtnTemplate").click(function () {
            window.location.href = config.base + "production/productionPlan/admin/simpleWorkOrder/template";
        });
        // 导入excel
        $('#uploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'production/productionPlan/admin/simpleWorkOrder/importExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });
        });
        // 导出excel
        $('#simpleWorkOrderBtnExport').click(function () {
            var checkRows = table.checkStatus('simpleWorkOrderTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

        // 渲染下拉框数据
        function loadSelectHtml(data, tips, htmltarget, type, formName) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type === 1) {
                    html += `<option value='${data[i].skuCode}' >${data[i].skuCode}</option>`;
                } else if(type === 2) {
                    html += `<option value='${data[i].id}' >${data[i].name}</option>`;
                }
            }

            $("form[lay-filter='" + formName + "']  select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }


        // 导出
        $('#workOrderExport').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();

            if (sTime == "" && eTime == "") {
                layer.msg('请先选择创建时间！')
            } else {

                location.href = config.base + 'production/productionPlan/admin/simpleWorkOrder/export?startCreateTime=' + sTime + '&endCreateTime=' + eTime + '&enterpriseCode=' + config.getUser().enterpriseCode;
            }
        });

    });
</script>